<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>FormValidation &rarr; SemanticUI demo</title>

    <link rel="stylesheet" href="http://cdn.jsdelivr.net/semantic-ui/1.2.0/semantic.min.css"/>
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" />
    <link rel="stylesheet" href="../../dist/css/formValidation.css"/>

    <script type="text/javascript" src="../../vendor/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="http://cdn.jsdelivr.net/semantic-ui/1.2.0/semantic.min.js"></script>

    <script type="text/javascript" src="../../dist/js/formValidation.js"></script>
    <script type="text/javascript" src="../../dist/js/framework/semantic.js"></script>

    <style type="text/css">
    body {
        padding: 50px 0;
    }
    </style>
</head>
<body>
    <div class="ui grid">
        <div class="four wide column"></div>

        <div class="eight wide column">
            <h2 class="ui dividing header">Semantic-UI Form</h2>

            <form id="horizontalForm" class="ui grid form">
                <div class="row field">
                    <label class="four wide column">Full name</label>
                    <div class="six wide column">
                        <div class="ui input icon">
                            <input name="firstName" type="text" placeholder="First name" />
                        </div>
                    </div>
                    <div class="six wide column">
                        <div class="ui input icon">
                            <input name="lastName" type="text" placeholder="Last name" />
                        </div>
                    </div>
                </div>

                <div class="row field">
                    <label class="four wide column">Username</label>
                    <div class="eight wide column">
                        <div class="ui input icon">
                            <input name="username" type="text" placeholder="Username" />
                        </div>
                    </div>
                </div>

                <div class="row field">
                    <label class="four wide column">Email address</label>
                    <div class="eight wide column">
                        <div class="ui input icon">
                            <input name="email" type="text" placeholder="Email address" />
                        </div>
                    </div>
                </div>

                <div class="row field">
                    <label class="four wide column">Password</label>
                    <div class="eight wide column">
                        <div class="ui input icon">
                            <input name="password" type="password" placeholder="Password" />
                        </div>
                    </div>
                </div>

                <div class="row field">
                    <label class="four wide column">Gender</label>
                    <div class="ten wide column">
                        <div class="ui radio">
                            <input name="gender" type="radio" value="male" /> <label>Male</label>
                        </div>
                        <div class="ui radio">
                            <input name="gender" type="radio" value="female" /> <label>Female</label>
                        </div>
                        <div class="ui radio">
                            <input name="gender" type="radio" value="other" /> <label>Other</label>
                        </div>
                    </div>
                </div>

                <div class="row field">
                    <label class="four wide column">
                        <span class="right" id="captchaOperation"></span>
                    </label>
                    <div class="four wide column">
                        <div class="ui input icon">
                            <input type="text" name="captcha" />
                        </div>
                    </div>
                </div>

                <div class="row field">
                    <label class="four wide column"></label>
                    <div class="ten wide column">
                        <div class="ui checkbox">
                            <input name="agree" type="checkbox" /> <label>Agree with the terms and conditions</label>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <label class="four wide column"></label>
                    <div class="eight wide column">
                        <button type="submit" class="ui primary button">Submit</button>
                    </div>
                </div>
            </form>
        </div>

        <div class="four wide column"></div>
    </div>

<script type="text/javascript">
$(document).ready(function() {
    // Generate a simple captcha
    function randomNumber(min, max) {
        return Math.floor(Math.random() * (max - min + 1) + min);
    };
    $('#captchaOperation').html([randomNumber(1, 100), '+', randomNumber(1, 200), '='].join(' '));

    $('#horizontalForm').formValidation({
        framework: 'semantic',
        icon: {
            valid: 'checkmark icon',
            invalid: 'remove icon',
            validating: 'refresh icon',
            feedback: 'fv-control-feedback'
        },
        fields: {
            firstName: {
                row: '.small-6',
                validators: {
                    notEmpty: {
                        message: 'The first name is required'
                    }
                }
            },
            lastName: {
                row: '.small-6',
                validators: {
                    notEmpty: {
                        message: 'The last name is required'
                    }
                }
            },
            username: {
                message: 'The username is not valid',
                validators: {
                    notEmpty: {
                        message: 'The username is required'
                    },
                    stringLength: {
                        min: 6,
                        max: 30,
                        message: 'The username must be more than 6 and less than 30 characters long'
                    },
                    regexp: {
                        regexp: /^[a-zA-Z0-9_\.]+$/,
                        message: 'The username can only consist of alphabetical, number, dot and underscore'
                    }
                }
            },
            email: {
                validators: {
                    notEmpty: {
                        message: 'The email address is required'
                    },
                    emailAddress: {
                        message: 'The input is not a valid email address'
                    }
                }
            },
            password: {
                validators: {
                    notEmpty: {
                        message: 'The password is required'
                    },
                    different: {
                        field: 'username',
                        message: 'The password cannot be the same as username'
                    }
                }
            },
            gender: {
                validators: {
                    notEmpty: {
                        message: 'The gender is required'
                    }
                }
            },
            captcha: {
                validators: {
                    callback: {
                        message: 'Wrong answer',
                        callback: function(value, validator) {
                            var items = $('#captchaOperation').html().split(' '), sum = parseInt(items[0]) + parseInt(items[2]);
                            return value == sum;
                        }
                    }
                }
            },
            agree: {
                validators: {
                    notEmpty: {
                        message: 'You must agree with the terms and conditions'
                    }
                }
            }
        }
    });

    // Use checkbox element
    // http://semantic-ui.com/modules/checkbox.html
    $('.ui.checkbox').checkbox();
});
</script>
</body>
</html>